package com.gxc.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author GongXincheng
 * @since 2019-09-03 10:22
 */
@Configuration
public class QueueConfigBean {

    public static final String TOPIC_EXCHANGE_NAME = "gxcExchange";
    public static final String TOPIC_QUEUE_1 = "com.gxc.exchangeQueue-1";
    public static final String TOPIC_QUEUE_2 = "com.exchangeQueue-2";

    @Value("${gxc.queue.name.test-queue}")
    public String testQueue;


    @Bean
    public Queue testQueue() {
        return new Queue(testQueue);
    }


    @Bean
    public TopicExchange myTopicExchange() {
        return new TopicExchange("gxcExchange", true, false);
    }

    @Bean
    public Queue topicQueue1() {
        return new Queue(TOPIC_QUEUE_1);
    }

    @Bean
    public Queue topicQueue2() {
        return new Queue(TOPIC_QUEUE_2);
    }

    @Bean
    public Binding topicBinding() {
        return BindingBuilder.bind(topicQueue1()).to(myTopicExchange()).with("com.#");
    }
}
